package com.wikimi.check.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wikimi.check.dao.CheckMapper;
import com.wikimi.domain.Check;
import com.wikimi.domain.Kid;

@Transactional
@Service
public class CheckServiceImpl implements CheckService {

	@Autowired
	private CheckMapper mapper;
	
	private static final int LINES_PER_PAGE = 5;
	
	@Override
	@Transactional(readOnly = true)
	public List<Check> getAllPathByPage(Integer page, String id) {
		// TODO Auto-generated method stub
		int begin = (page.intValue() - 1) * LINES_PER_PAGE + 1;
		int end = page.intValue() * LINES_PER_PAGE;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("begin", begin);
		map.put("end", end);
		map.put("id", id);
		
		List<Check> checks = mapper.getAllPathByPage(map);
		
		return checks;
	}
	
	@Override
	@Transactional(readOnly = true)
	public List<Check> getAllPathByTime(Integer page, String id, String cust_i_hp_no, String startTime) {
		// TODO Auto-generated method stub
		int begin = (page.intValue() - 1) * LINES_PER_PAGE + 1;
		int end = page.intValue() * LINES_PER_PAGE;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("begin", begin);
		map.put("end", end);
		map.put("id", id);
		map.put("cust_i_hp_no", cust_i_hp_no);
		map.put("startTime", startTime);
		
		List<Check> checks = mapper.getAllPathByTime(map);
		
		return checks;
	}
	
	@Override
	@Transactional(readOnly = true)
	public Integer getPathTotalById(String id) {	
		return mapper.getPathTotalById(id);
	}
	
	@Override
	@Transactional(readOnly = true)
	public Integer getPathTotalByIdTime(String id, String cust_i_hp_no, String startTime) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", id);
		map.put("cust_i_hp_no", cust_i_hp_no);
		map.put("startTime", startTime);
		
		return mapper.getPathTotalByIdTime(map);
	}
	
	@Override
	@Transactional(readOnly = true)
	public List<Kid> getAllKidById(String id) {
		return mapper.getAllKidById(id);
	}
}
